package com.ruoyi.system.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.vo.TransferData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.SchoolStudentMapper;
import com.ruoyi.system.domain.SchoolStudent;
import com.ruoyi.system.service.ISchoolStudentService;
import com.ruoyi.system.domain.vo.SchoolStudentVo;

/**
 * 学生信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-06-29
 */
@Service
public class SchoolStudentServiceImpl implements ISchoolStudentService 
{
    @Autowired
    private SchoolStudentMapper schoolStudentMapper;

    /**
     * 查询学生信息
     * 
     * @param id 学生信息主键
     * @return 学生信息
     */
    @Override
    public SchoolStudent selectSchoolStudentById(Long id)
    {
        return schoolStudentMapper.selectSchoolStudentById(id);
    }

    /**
     * 查询学生信息列表
     * 
     * @param schoolStudent 学生信息
     * @return 学生信息
     */
    @Override
    public List<SchoolStudent> selectSchoolStudentList(SchoolStudent schoolStudent)
    {
        return schoolStudentMapper.selectSchoolStudentList(schoolStudent);
    }

    /**
     * 新增学生信息
     * 
     * @param schoolStudent 学生信息
     * @return 结果
     */
    @Override
    public int insertSchoolStudent(SchoolStudent schoolStudent)
    {
        schoolStudent.setCreateTime(DateUtils.getNowDate());
        return schoolStudentMapper.insertSchoolStudent(schoolStudent);
    }

    /**
     * 修改学生信息
     * 
     * @param schoolStudent 学生信息
     * @return 结果
     */
    @Override
    public int updateSchoolStudent(SchoolStudent schoolStudent)
    {
        return schoolStudentMapper.updateSchoolStudent(schoolStudent);
    }

    /**
     * 批量删除学生信息
     * 
     * @param ids 需要删除的学生信息主键
     * @return 结果
     */
    @Override
    public int deleteSchoolStudentByIds(Long[] ids)
    {
        return schoolStudentMapper.deleteSchoolStudentByIds(ids);
    }

    /**
     * 删除学生信息信息
     * 
     * @param id 学生信息主键
     * @return 结果
     */
    @Override
    public int deleteSchoolStudentById(Long id)
    {
        return schoolStudentMapper.deleteSchoolStudentById(id);
    }

    /**
     * 查询学生信息列表（带班级信息）
     *
     * @param schoolStudent 学生信息
     * @return 学生信息
     */
    @Override
    public List<SchoolStudentVo> selectSchoolStudentVoList(SchoolStudent schoolStudent)
    {
        return schoolStudentMapper.selectSchoolStudentVoList(schoolStudent);
    }

    public List<Long> getStudentsIdsByClassId(Long id) {
        return schoolStudentMapper.selectStudentIdsByClassId(id);
    }

    @Override
    public List<TransferData> getNoClassAndThisClassStudentsInfo(Long id) {
        return schoolStudentMapper.selectNoClassAndThisClassStudentsInfo(id);
    }

    @Override
    public void updateThisClassStudents(List<Long> ids, Long classId) {
        //删除原来的本班学生，然后再把新的本班学生的id集合的所有学生班级id改为本班id✅
        //1、 删除原来的本班学生
        schoolStudentMapper.deleteThisClassStudents(classId);

        //2、然后再把新的本班学生的ids集合的所有学生班级id改为本班id
        schoolStudentMapper.addStudentsInThisClass(ids, classId);
    }


}
